public class ShoppingCart {
    private Fruit[] fruits;
    private int[] weight;

    // 构造器
    public ShoppingCart() {
        fruits = new Fruit[3];
        weight = new int[3];
        fruits[0] = new Fruit("Apple", 8);
        fruits[1] = new Fruit("Strawberry", 13);
        fruits[2] = new Fruit("Mango", 20);
    }

    // 计算购买商品的总价（未考虑促销活动）
    public double calculateTotalPrice() {
        double totalPrice = 0;
        for (int i = 0; i < fruits.length; i++) {
            totalPrice += fruits[i].getPrice() * getWeight(i);
        }
        return totalPrice;
    }

    // 计算购买商品的总价（考虑草莓8折促销活动）
    public double calculateTotalPriceWithStrawberryDiscount() {
        double totalPrice = 0;
        for (int i = 0; i < fruits.length; i++) {
            if ("Strawberry".equals(fruits[i].getName())) {
                totalPrice += fruits[i].getPrice() * 0.8 * getWeight(i);
            } else {
                totalPrice += fruits[i].getPrice() * getWeight(i);
            }
        }
        return totalPrice;
    }

    // 计算购买商品的总价（考虑购物满100减10块促销活动）
    public double calculateTotalPriceWithFullReduction() {
        double totalPrice = calculateTotalPriceWithStrawberryDiscount();
        if (totalPrice >= 100) {
            totalPrice -= 10;
        }
        return totalPrice;
    }

    // setter方法
    public void setWeight(int fruitIndex, int value) {
        weight[fruitIndex] = value;
    }

    // getter方法
    public int getWeight(int fruitIndex) {
        return weight[fruitIndex];
    }
}

